using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class PlayerStateBar : MonoBehaviour {
    
    public Image healthImage;       // 血条
    public Image healthDelayImage;  // 血条延迟
    public Image powerImage;        // 能量条
    public bool isRecovering;       // 能量条是否处于恢复状态
    public Character curCharacter;

    private void Update() {
        // 血条的延迟滚动
        if (healthDelayImage.fillAmount > healthImage.fillAmount) {
            healthDelayImage.fillAmount -= Time.deltaTime;
        }

        // 能量条是否正处于恢复状态
        if (isRecovering) {
            float persentage = curCharacter.curPower / curCharacter.maxPower;
            powerImage.fillAmount = persentage;

            if (persentage >= 1) {
                isRecovering = false;
                return;
            }
        }
    }

    /// <summary>
    /// 接收Health的变更百分比
    /// </summary>
    /// <param name="persentage">百分比：Current/Max</param>
    public  void OnHealthChange(float persentage) {
        healthImage.fillAmount = persentage;
    }

    public void OnPowerChange(Character character) {
        isRecovering = true;
        curCharacter = character;
    }

}